﻿using System;
using System.Xml.Serialization;

namespace GMAC.ReportingSystem.Business.Entities
{
    /// <summary>
    /// Represents the permissions for a role.
    /// </summary>
    [XmlRoot(ElementName = "Security")]
    [Serializable]
    public class Security
    {
        /// <summary>
        /// Gets or sets the menus.
        /// </summary>
        /// <value>The menus.</value>
        [XmlArray(ElementName = "Menus")]
        public MenuCollection Menus { get; set; }

        [XmlArray(ElementName = "Entities")]
        [XmlArrayItem(ElementName = "Entity")]
        public EntitiesSecurityCollection Entities { get; set; }

        [XmlArray(ElementName = "Reports")]
        [XmlArrayItem(ElementName = "Report")]
        public ReportCollection Reports { get; set; }

        public EntitySecurity GetEntitySecurity(string entityName)
        {
            if (Entities != null)
            {
                foreach (var entity in Entities)
                {
                    if (entity.EntityName == entityName)
                    {
                        return entity;
                    }
                }
            }
            return null;
        }

        public Report GetReport(Guid reportID)
        {
            if (Reports != null)
            {
                foreach (var report in Reports)
                {
                    if (report.ReportID == reportID)
                        return report;
                }
            }
            return null;
        }
    }
}
